package com.moyu.user.controller;

import com.moyu.common.core.controller.BaseController;
import com.moyu.common.core.domain.R;
import com.moyu.common.core.domain.TableDataInfo;
import com.moyu.common.security.exception.ServiceException;
import com.moyu.user.domain.role.dto.PermissionByRoleQueryDTO;
import com.moyu.user.domain.role.dto.RolePermissionSavaDTO;
import com.moyu.user.domain.role.dto.RoleQueryDTO;
import com.moyu.user.domain.role.dto.RoleSaveDTO;
import com.moyu.user.service.IRoleService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 角色控制器
 *
 * @Author 赵彦博
 * @Date 2025/3/25 18:28
 */
@RestController
@RequestMapping("/role")
@Tag(name = "角色接口")
public class RoleController extends BaseController {

    @Autowired
    private IRoleService roleService;

    @GetMapping("/list")
    public TableDataInfo list(RoleQueryDTO roleQueryDTO) {
        return getTableDataInfo(roleService.list(roleQueryDTO));
    }

    @DeleteMapping("/{roleId}")
    public R deleteRole(@PathVariable Long roleId) {
        return toR(roleService.deleteRole(roleId));
    }

    @GetMapping("/permission/{roleId}")
    public TableDataInfo getRolePermissionList(PermissionByRoleQueryDTO dto) {
        return getTableDataInfo(roleService.getRolePermissionList(dto));
    }

    @PostMapping("/add")
    public R addRole(@RequestBody RoleSaveDTO roleSaveDTO) {
        return toR(roleService.addRole(roleSaveDTO));
    }

    @DeleteMapping("/delete/permission")
    public R removeRolePermission(@RequestBody PermissionByRoleQueryDTO dto) {
        return toR(roleService.removeRolePermission(dto));
    }


    @GetMapping("/availablePermission")
    public TableDataInfo availablePermission(PermissionByRoleQueryDTO dto) {
        return getTableDataInfo(roleService.availablePermission(dto));
    }

    @PostMapping("/add/permission")
    public R addRolePermission(@RequestBody RolePermissionSavaDTO rolePermissionSavaDTO){
        return toR(roleService.addRolePermission(rolePermissionSavaDTO));
    }
}
